package bs.controller;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import bs.entity.User;
import bs.service.BookService;
import bs.util.ResponseUtil;
import bs.util.StringUtil;

/**
 * 
 * UserBookController
 *
 * @author 姜治昊
 * @time 2017年12月4日 上午10:25:37
 */
@Controller
@RequestMapping("userbook")
public class UserBookController {
	
	@Autowired
	private BookService bookService;
	
	/**
	 * 删除用户-图书关系
	 */
	@RequestMapping(value="/{bookIds}", method=RequestMethod.DELETE, produces="text/plain;charset=UTF-8")
	public void deleteBooks(HttpSession session, HttpServletResponse response, @PathVariable("bookIds") String bookIds) {
		User user = (User) session.getAttribute("LOGIN_USER");
		int result = bookService.deleteBooksByUser(user.getUserId(), StringUtil.strToIntArr(bookIds));
		ResponseUtil.write(response, result);
	}

}
